package io.renren.modules.usian.service.impl;

import io.renren.modules.usian.entity.StudnetEntity;
import io.renren.modules.usian.entity.TeacherEntity;
import io.renren.modules.usian.service.StudnetService;
import io.renren.modules.usian.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.usian.dao.ClasssDao;
import io.renren.modules.usian.entity.ClasssEntity;
import io.renren.modules.usian.service.ClasssService;


@Service("classsService")
public class ClasssServiceImpl extends ServiceImpl<ClasssDao, ClasssEntity> implements ClasssService {
    @Autowired
    private StudnetService studnetService;
    @Autowired
    private TeacherService teacherService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ClasssEntity> page = this.page(
                new Query<ClasssEntity>().getPage(params),
                new QueryWrapper<ClasssEntity>()
        );

        List<ClasssEntity> list = page.getRecords();
        list.stream().map((classs)->{
            StudnetEntity byId = studnetService.getById(classs.getCid());
            classs.setCname(byId.getName());
            return classs;
        }).collect(Collectors.toList());

        list.stream().map((teacher)->{
            TeacherEntity byId = teacherService.getById(teacher.getTid());
            teacher.setTname(byId.getName());
            TeacherEntity byId1 = teacherService.getById(teacher.getHid());
            teacher.setHname(byId1.getName());
            return teacher;
        }).collect(Collectors.toList());



        return new PageUtils(page);
    }

}